<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Bomberman:  Fichier source de /home/ph3w/Bureau/lif7-bomberman/outils.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Généré par Doxygen 1.7.1 -->
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="header">
  <div class="headertitle">
<h1>/home/ph3w/Bureau/lif7-bomberman/outils.cpp</h1>  </div>
</div>
<div class="contents">
<a href="outils_8cpp.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="outils_8h.html">outils.h</a>&quot;</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00004"></a>00004 <span class="comment">* @fn int myRand( int a, int b )</span>
<a name="l00005"></a>00005 <span class="comment">* @brief Créer un nombre aléatoire compris entre a et b</span>
<a name="l00006"></a>00006 <span class="comment">*/</span>
<a name="l00007"></a><a class="code" href="outils_8h.html#a5ee0533ff07a519f3fce335a2f57f157">00007</a> <span class="keywordtype">int</span> <a class="code" href="outils_8cpp.html#a5ee0533ff07a519f3fce335a2f57f157" title="Créer un nombre aléatoire compris entre a et b.">myRand</a>( <span class="keywordtype">int</span> a, <span class="keywordtype">int</span> b )
<a name="l00008"></a>00008 {
<a name="l00009"></a>00009     <span class="keywordtype">double</span> r;
<a name="l00010"></a>00010 
<a name="l00011"></a>00011     r = (double) rand() / RAND_MAX;
<a name="l00012"></a>00012     r *= (double) b+1.-a;
<a name="l00013"></a>00013     r += (double) a;
<a name="l00014"></a>00014     <span class="keywordflow">return</span> (<span class="keywordtype">int</span>) r;
<a name="l00015"></a>00015 }
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00019"></a>00019 <span class="comment">* @fn unsigned char getTailleNombre( int nb )</span>
<a name="l00020"></a>00020 <span class="comment">* @brief Calcule la longueur d&#39;un nombre.</span>
<a name="l00021"></a>00021 <span class="comment">* @param[in] nb Le nombre dont on veut savoir la taille</span>
<a name="l00022"></a>00022 <span class="comment">* @return Renvoie le nombre de chiffre qui compose le nombre</span>
<a name="l00023"></a>00023 <span class="comment">*</span>
<a name="l00024"></a>00024 <span class="comment">* Exemple getTailleNombre(-10) =&gt; 3&lt;br /&gt;</span>
<a name="l00025"></a>00025 <span class="comment">*/</span>
<a name="l00026"></a><a class="code" href="outils_8h.html#ab0a855d1eae4c34ffa5b7805b268dbbe">00026</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="outils_8cpp.html#ab0a855d1eae4c34ffa5b7805b268dbbe" title="Calcule la longueur d&amp;#39;un nombre.">getTailleNombre</a>( <span class="keywordtype">int</span> nb )
<a name="l00027"></a>00027 {
<a name="l00028"></a>00028     <span class="keywordflow">if</span>( nb &lt; 0 )<span class="comment">// On met le nombre en positif si ce n&#39;est pas le cas</span>
<a name="l00029"></a>00029         <span class="keywordflow">return</span> <a class="code" href="outils_8cpp.html#ab0a855d1eae4c34ffa5b7805b268dbbe" title="Calcule la longueur d&amp;#39;un nombre.">getTailleNombre</a>( (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) (nb*(-1)) )+1;<span class="comment">// +1 pour le symbole négatif</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031     <span class="keywordflow">return</span> <a class="code" href="outils_8cpp.html#ab0a855d1eae4c34ffa5b7805b268dbbe" title="Calcule la longueur d&amp;#39;un nombre.">getTailleNombre</a>( (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) nb );
<a name="l00032"></a>00032 }
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00036"></a>00036 <span class="comment">* @fn unsigned char getTailleNombre( unsigned int nb )</span>
<a name="l00037"></a>00037 <span class="comment">* @brief Calcule la longueur d&#39;un nombre.</span>
<a name="l00038"></a>00038 <span class="comment">* @param[in] nb Le nombre dont on veut savoir la taille</span>
<a name="l00039"></a>00039 <span class="comment">* @return Renvoie le nombre de chiffre qui compose le nombre</span>
<a name="l00040"></a>00040 <span class="comment">*</span>
<a name="l00041"></a>00041 <span class="comment">* Exemple getTailleNombre(122) =&gt; 3</span>
<a name="l00042"></a>00042 <span class="comment">*/</span>
<a name="l00043"></a><a class="code" href="outils_8h.html#a74636b55902344092d141b0c3c96051e">00043</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="outils_8cpp.html#ab0a855d1eae4c34ffa5b7805b268dbbe" title="Calcule la longueur d&amp;#39;un nombre.">getTailleNombre</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nb )
<a name="l00044"></a>00044 {
<a name="l00045"></a>00045     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> taille_NB;
<a name="l00046"></a>00046     <span class="keywordflow">for</span>( taille_NB=1; nb&gt;=10; taille_NB++ )
<a name="l00047"></a>00047         nb /=10;
<a name="l00048"></a>00048 
<a name="l00049"></a>00049     <span class="keywordflow">return</span> taille_NB;
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 
<a name="l00053"></a>00053 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00054"></a>00054 <span class="comment">* @fn char* trimString( char texte[] )</span>
<a name="l00055"></a>00055 <span class="comment">* @brief Vire les espaces avant et après une chaine de caractère</span>
<a name="l00056"></a>00056 <span class="comment">* @param[in,out] texte Le texte a trim. Le texte est directement modifié</span>
<a name="l00057"></a>00057 <span class="comment">* @return Renvoie le pointeur @e texte</span>
<a name="l00058"></a>00058 <span class="comment">*</span>
<a name="l00059"></a>00059 <span class="comment">* Exemple : &quot;  toto &quot; =&gt; &quot;toto&quot;</span>
<a name="l00060"></a>00060 <span class="comment">*/</span>
<a name="l00061"></a><a class="code" href="outils_8h.html#a6de899e6ec4432e58a7466ed1e60c3f8">00061</a> <span class="keywordtype">char</span>* <a class="code" href="outils_8cpp.html#a867f58846060922b50a272361337cc96" title="Vire les espaces avant et après une chaine de caractère.">trimString</a>( <span class="keywordtype">char</span> texte[] )
<a name="l00062"></a>00062 {
<a name="l00063"></a>00063     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>    posDebut=0,
<a name="l00064"></a>00064                     posFin=strlen(texte)-2;<span class="comment">// -2 car -1 =&gt; &#39;\0&#39; et 0 =&gt; out du tableau</span>
<a name="l00065"></a>00065 
<a name="l00066"></a>00066     <span class="comment">// On remplis tous les espaces qui sont en fin de chaine de &#39;\0&#39;</span>
<a name="l00067"></a>00067     <span class="keywordflow">while</span>( isspace(*(texte+posFin)) &amp;&amp; texte[posFin] &amp;&amp; posFin&gt;0 )
<a name="l00068"></a>00068     {
<a name="l00069"></a>00069         texte[posFin] = 0;
<a name="l00070"></a>00070         posFin--;
<a name="l00071"></a>00071     }
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     <span class="comment">// On trouve la 1ère lettre qui n&#39;est pas un espace</span>
<a name="l00074"></a>00074     <span class="keywordflow">while</span>( isspace(*(texte+posDebut)) &amp;&amp; texte[posDebut] &amp;&amp; ++posDebut&gt;0 );
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     <span class="comment">// On déplace les caractères</span>
<a name="l00077"></a>00077     <span class="keywordflow">return</span> strcpy(texte, texte+posDebut);
<a name="l00078"></a>00078 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Généré le Fri Jan 21 2011 01:21:27 pour Bomberman par&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>
